
Imports cmplib01



Public Class frmChitSpreadsheet

    Const c_MODULE As String = "frmChitSpreadsheet"

    Private Enum viewMode
        installation = 0
        unit = 1
    End Enum

    Private _ptrGame As CampaignerGameData
    Private _view As viewMode = viewMode.unit
    Private _moveTypes() As String


    Public Overloads Sub ShowDialog(ByRef game As CampaignerGameData, ByVal moveTypes() As String)

        _ptrGame = game
        _moveTypes = moveTypes
        Populate()

        MyBase.ShowDialog()

    End Sub

    Private Sub Populate()
        Try

            If _view = viewMode.installation Then

                If _ptrGame.ObjectiveTypes.Count = 0 Then Exit Sub

                Dim arr(_ptrGame.ObjectiveTypes.Count - 1) As InstallationDisplay
                Dim inst As ObjectiveType
                'Dim k As String
                Dim i As Integer = 0

                For Each inst In _ptrGame.ObjectiveTypes
                    '   inst = _ptrGame.ObjectiveTypes.Item(k)
                    Dim instie As New InstallationDisplay
                    With instie
                        .Name = inst.TypeName
                        .Los = inst.LOS
                        .Zoc = inst.ZOCRange
                    End With

                    arr(i) = instie

                    i += 1
                Next

                dgdSpreadsheet.DataSource = arr

                dgdSpreadsheet.Columns.Item("Name").DisplayIndex = 0
                dgdSpreadsheet.Columns.Item("Name").HeaderText = "Installation Name"

                dgdSpreadsheet.Columns.Item("los").DisplayIndex = 1
                dgdSpreadsheet.Columns.Item("los").HeaderText = "Detection Range"

                dgdSpreadsheet.Columns.Item("zoc").DisplayIndex = 2
                dgdSpreadsheet.Columns.Item("zoc").HeaderText = "Zone Of Control"

            Else

                If _ptrGame.UnitTypes.Count = 0 Then Exit Sub

                Dim arr(_ptrGame.UnitTypes.Count - 1) As UnitDisplay
                Dim unie As UnitType
                'Dim k As String
                Dim i As Integer = 0

                For Each unie In _ptrGame.UnitTypes
                    Dim uD As New UnitDisplay

                    With uD
                        .Unit_Name = unie.TypeName
                        .Zone_Of_Control = unie.ZOCRange
                        .Move_Speed = unie.MovementSpeed
                        .Move_Type = _moveTypes(unie.MovementClassID)
                        .Detection_Range = unie.LOS
                        .Suggested_PV = unie.SuggestedPointValue
                    End With

                    arr(i) = uD

                    i += 1
                Next

                dgdSpreadsheet.DataSource = arr

                For i = 0 To dgdSpreadsheet.Columns.Count - 1
                    dgdSpreadsheet.Columns.Item(i).HeaderText = dgdSpreadsheet.Columns.Item(i).Name.Replace("_", " ")
                Next

                '// now put unit name first
                dgdSpreadsheet.Columns.Item("Unit_Name").DisplayIndex = 0
                dgdSpreadsheet.Columns.Item("Move_Speed").DisplayIndex = 1
                dgdSpreadsheet.Columns.Item("Move_Type").DisplayIndex = 2
                dgdSpreadsheet.Columns.Item("Detection_Range").DisplayIndex = 3
                dgdSpreadsheet.Columns.Item("Zone_Of_Control").DisplayIndex = 4
                dgdSpreadsheet.Columns.Item("Suggested_PV").DisplayIndex = 5

            End If

        Catch ex As Exception
            HandleException(c_MODULE, ex)
        End Try
    End Sub



    Private Class UnitDisplay
        Private _UnitName As String
        Private _ZOC As Single
        Private _LOSRange As Single
        Private _MoveSpeed As Single
        Private _MoveType As String
        Private _SuggestedPV As Integer

        Property Suggested_PV() As Integer
            Get
                Return _SuggestedPV
            End Get
            Set(ByVal value As Integer)
                _SuggestedPV = value
            End Set
        End Property

        Property Unit_Name() As String
            Get
                Return _UnitName
            End Get
            Set(ByVal value As String)
                _UnitName = value
            End Set
        End Property

        Property Zone_Of_Control() As Single
            Get
                Return _ZOC
            End Get
            Set(ByVal value As Single)
                _ZOC = value
            End Set
        End Property

        Property Detection_Range() As Single
            Get
                Return _LOSRange
            End Get
            Set(ByVal value As Single)
                _LOSRange = value
            End Set
        End Property

        Property Move_Speed() As Single
            Get
                Return _MoveSpeed
            End Get
            Set(ByVal value As Single)
                _MoveSpeed = value
            End Set
        End Property

        Property Move_Type() As String
            Get
                Return _MoveType
            End Get
            Set(ByVal value As String)
                _MoveType = value
            End Set
        End Property

    End Class

    Private Class InstallationDisplay
        Private _name As String
        Private _zoc As Single
        Private _los As Single

        Property Name() As String
            Get
                Return _name
            End Get
            Set(ByVal value As String)
                _name = value
            End Set
        End Property

        Property Zoc() As Single
            Get
                Return _zoc
            End Get
            Set(ByVal value As Single)
                _zoc = value
            End Set
        End Property

        Property Los() As Single
            Get
                Return _los
            End Get
            Set(ByVal value As Single)
                _los = value
            End Set
        End Property

    End Class

    Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.Hide()
    End Sub
End Class

